#ifndef _MAIN_VIEWER_H_
#define _MAIN_VIEWER_H_

#include "AdapterWidget.h"
#include "HomeGrid.h"
#include "SceneManagerModel.h"
#include "SelectionManager.h"
#include "PickHandler.h"
#include <osg/Vec2s>
#include <osg/PositionAttitudeTransform>
#include <QtGUI/QItemSelection>

class MainViewer : public ViewerQT
{
	Q_OBJECT

public:
	MainViewer();

	void setModel(SceneManagerModel* model);
	void setItemSelectionModel(class QItemSelectionModel* selectionModel);

	SceneManagerModel* getModel() const { return m_rSceneManager.get(); }

protected:
	virtual void dragEnterEvent(QDragEnterEvent *event);
	virtual void dragLeaveEvent(QDragLeaveEvent *event);
	virtual void dragMoveEvent(QDragMoveEvent *event);
	virtual void dropEvent(QDropEvent *event);

private slots:
	void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);

private:
	enum FileType {Image, Model, Unknown};

private:
    void loadAndAddObjectToSceneManager(const QString& filePath);
	void updateHomePosition(const osg::Vec2s& dimensions);
    osg::PositionAttitudeTransform* loadNode(const QString& filePath);
	static FileType getFileTypeFromExtension(const QString& filePath);
	void updateDraggedObjectPositionFromMousePosition(const QPoint& pos);

private:
	osg::ref_ptr<SceneManagerModel> m_rSceneManager;
	osg::ref_ptr<SelectionManager> m_rSelectionManager;
	osg::ref_ptr<PickHandler> m_rPickHandler;
	class QItemSelectionModel* m_pSelectionModel;
	FileType m_DragType;
	HomeGrid m_HomeGrid;
};

#endif
